<template>
	<div class="movieglist">
		<div class="dd">
			<div class="d1">
				<div class="d2">
					<p class="p1">书籍管理</p>
					—
					<p>书籍列表</p>
				</div>
				<div class="im">
					<el-button icon="el-icon-refresh-right"></el-button>
				</div>
			</div>
			<div class="hr"></div>
			<div class="d6">
				<input placeholder="请输入内容" v-model="keywords"></input>
				<el-button icon="el-icon-search" @click="sos()"></el-button>
			</div>
			<div class="d3">
				<el-button @click="add()">添加书籍</el-button>
			</div>
			<el-table  :data="books" class="d4" border>
				<el-table-column prop="id" label="序号"></el-table-column>
				<el-table-column prop="name" label="书籍名称"></el-table-column>
				<el-table-column prop="sn" label="书籍序号"></el-table-column>
				<el-table-column prop="price" label="书籍价格"></el-table-column>
				<el-table-column prop="pic" label="书籍海报">
					<template slot-scope="scope">
						<el-image :src="`http://127.0.0.1/api/public/showimg/${scope.row.pic}`"></el-image>
					</template>
				</el-table-column>
				<el-table-column prop="maker" label="书籍出版社"></el-table-column>
				<el-table-column prop="date" label="出版时间"></el-table-column>
				<el-table-column prop="author" label="作者"></el-table-column>
				<el-table-column prop="stock" label="库存"></el-table-column>
				
				<el-table-column label="管理">
					<template slot-scope="scope">
						<el-button type="primary" icon="el-icon-edit" @click="Edit(scope.row)">修改</el-button>
						</el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination :page-size="num" @current-change="pageChange" :current-page="$store.state.pagestart"
				layout="prev, pager, next" :total="total">
			</el-pagination>
		</div>
	</div>
</template>

<script>
	export default {
		name: 'MoviegList',
		data() {
			return {
				keywords:[],
				books:[],
				start: 1,
				num: 5,
				total:0,
				onType : -1
			}
		},
		methods: {
			pageChange(x) {
				
				this.$store.state.pagestart = x;
				this.$store.state.pagenum = this.num;
				this.start = x;
				console.log("this.$store.state.pagestart=" + this.$store.state.pagestart)
				this.$get("/api/adm/book/findByPage/" + x + "/" + this.num)
					.then(resp => {
						console.log(resp.data)
						this.books = resp.data.data.books; //当前页面 数据, 一般就是 this.num 要求行数
					})
			},
			getAllGoods() {
				this.$get("/api/adm/book/findByPage/" + this.start + "/" + this.num).then((resp) => {
					this.total = resp.data.data.total;//一共有几页
					this.books = resp.data.data.books;
					resp.data.data.books.forEach((item) => {
						let time = new Date(item.tmake)
						item.date = time.getFullYear() + '年' + time.getMonth() + '月' + time.getDay() +
							'日';
					})
					console.log(resp.data.data)
				})
			},
			Edit(arr) {
				console.log(55555)
				this.$router.push({
					path: '/home/updatelist',
					query: {
						arr
					}
				})
			},
			add() {
				this.$router.push({
					path: '/home/addmovlist',
				})
			},
			sos(){
				this.books = [];
				this.total = 0;
				this.curpage = 1;
				this.start = 1;
				this.onType = -1;
				let bookkey = new FormData();
				bookkey.append("key", this.keywords);
				this.$axios.post("http://127.0.0.1/api/public/book/findPageKey/" + this.start + "/" + this.num,bookkey
				).then(resp => {
					this.books = resp.data.data.books;
					this.total = resp.data.data.total;
					console.log("total=" + this.total);
					console.log(this.books);
				})
			},
			Delete(){
				
			}
		},
		mounted() {
			this.$store.state.pagenum = this.num;
			if (this.$store.state.pagestart) {
				this.start = this.$store.state.pagestart;
				this.num = this.$store.state.pagenum;
			}
			this.getAllGoods();
		},
	}
</script>

<style scoped>
	.movieglist {
		width: 85%;
	}

	.hr {
		margin-top: 1%;
		border: 1px solid #f4f4f4;
	}

	.dd {
		width: 95%;
		margin-left: 5%;
	}

	.d1 {
		display: flex;
		justify-content: space-between;
		margin-top: 2%;
	}

	.d1 .p1 {
		color: #a7adb2;
	}

	.d1 .im .el-button {
		background-color: #2da99d;
		color: white;
		border-radius: 5px;
	}

	.d2 {
		width: 17%;
		display: flex;
		justify-content: space-between;
	}

	.d3 button {
		margin-top: 1%;
		width: 9%;
		height: 35px;
		background-color: #009688;
		color: white;
		border-radius: 5%;
		border: none;
	}

	.d4 {
		margin-top: 2%;

	}

	.d6 {
		width: 20%;
		display: flex;
		margin-top: 1%;
	}

	.d6 .el-button {
		background-color: #009688;
		color: white;
		margin-left: 5%;
	}
</style>
